home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / attclck.arc / SETTIME.ASM < prev    next >
Encoding:
Assembly Source File  |  1985-12-04  |  2.3 KB  |  144 lines

  1.     page ,132
  2. ;
  3. ;    settime.asm
  4. ;
  5. ; The other day as I was entering the time for
  6. ; PC-DOS 3.1, I asked myself 'Why am I doing
  7. ; this?  The computer ahs a clock built in!'.
  8. ; This routine reads battery backed clock in the
  9. ; AT&T 6300 and sets DOS time from it.
  10. ;
  11.  
  12. settime    segment
  13.     assume    cs:settime, ds:settime
  14.     org    100h
  15.  
  16. start:
  17.     jmp    over_data
  18.  
  19. ;
  20. ;    data area
  21. ;
  22. ; putting the data at the beginning of the program
  23. ; allows the assembler to generate more efficient
  24. ; code.  (I always wondered why everyone did that)
  25. ;
  26.  
  27. ; set up string for display
  28. msg        db    'DOS time set to '
  29. ten_hour    db    30h
  30. unit_hour    db    30h
  31.         db    ':'
  32. ten_minute    db    30h
  33. unit_minute    db    30h
  34.         db    ':'
  35. ten_second    db    30h
  36. unit_second    db    30h
  37.         db    '.'
  38. tenth_second    db    30h
  39. hundreth_second    db    30h
  40.         db    '$'
  41.  
  42. ;
  43. ; code
  44. ;
  45.  
  46. over_data:
  47.  
  48. ;
  49. ; use AT&T bios to get the time.
  50. ; registers are set for an immediate call to the dos set time function
  51. ;
  52.  
  53.     mov    ah,-2        ; BIOS 'read clock' flag
  54.     int    1ah        ; call BIOS
  55.  
  56. ;
  57. ; set dos time
  58. ;
  59.  
  60.     mov    ah,2dh        ; DOS 'set time' function
  61.     int    21h        ; call DOS
  62.  
  63. ;
  64. ; convert values for display
  65. ;
  66.  
  67. ; hour
  68.  
  69.     mov    al,ch
  70.     call    conv_hex
  71.     add    ten_hour,al
  72.     add    unit_hour,ah
  73.  
  74. ; minute
  75.  
  76.     mov    al,cl
  77.     call    conv_hex
  78.     add    ten_minute,al
  79.     add    unit_minute,ah
  80.  
  81. ; second
  82.  
  83.     mov    al,dh
  84.     call    conv_hex
  85.     add    ten_second,al
  86.     add    unit_second,ah
  87.  
  88. ; tenth second
  89.  
  90.     mov    al,dl
  91.     call    conv_hex
  92.     add    tenth_second,al
  93.     add    hundreth_second,ah
  94.  
  95. ;
  96. ; suppress possible leading zero on displayed time
  97. ;
  98.  
  99.     cmp    ten_hour,30h    ; is the hour > ten?
  100.     jne    display_time    ; nope, just display time
  101.     mov    ten_hour,20h    ; set leading 0 to ' '
  102.  
  103. ; display the time
  104.  
  105. display_time:
  106.     mov    dx,offset msg    ; point to string to print
  107.     mov    ah,09h        ; DOS 'print string' function
  108.     int    21h        ; call DOS
  109.  
  110. ;
  111. ; exit to dos
  112. ;
  113.  
  114.     mov    ah,4ch        ; DOS 'terminate process' function
  115.     mov    al,00h        ; return code
  116.     int    21h        ; call DOS
  117.  
  118. ;
  119. ; convert hex to decimal
  120. ;
  121. ; input:
  122. ;    al - hex byte
  123. ;
  124. ; output:
  125. ;    ah - decimal units of hex byte
  126. ;    al - decimal tens of hex byte
  127. ;
  128. ; trash:
  129. ;    none
  130. ;
  131.  
  132. conv_hex:
  133.     push    dx        ; save dx (seconds values)
  134.     xor    ah,ah
  135.     mov    dh,0ah        ; dh = divisor
  136.     div    dh        ; ah = remainder = low BCD digit (0-9)
  137.                 ; al = quotient  = high BCD digit
  138.     pop    dx        ; restore dx
  139.     ret
  140.  
  141. settime    ends
  142.  
  143.     end    start
  144.